<?php

  // include base peer class
  require_once 'cms/core/om/om/BaseCategoryI18nPeer.php';
  
  // include object class
  include_once 'cms/core/om/CategoryI18n.php';


/**
 * Skeleton subclass for performing query and update operations on the 'category_i18n' table.
 *
 * 
 *
 * You should add additional methods to this class to meet the
 * application requirements.  This class will only be generated as
 * long as it does not already exist in the output directory.
 *
 * @package cms.core.om
 */	
class CategoryI18nPeer extends BaseCategoryI18nPeer {


    /**
     * The cached categories.
     */
    private static $categories = array();
    

    /**
     * Retrieve a i18n category
     */
    public static function getCategory($category, $language, $default) {

        if(!array_key_exists($category, self::$categories)) {

            $union = "category_i18n_id IN ( ".
                        "SELECT ( ".
                            "SELECT category_i18n_id ".
                                "FROM category_i18n ".
                                "WHERE category_i18n.category_id = category.category_id ".
                                "AND active=1 AND language_code = '".mysql_escape_string($language)."' ".
                                "AND category_i18n.category_id = " .$category." ".
                                "UNION ".
                                "SELECT category_i18n_id ".
                                "FROM category_i18n ".
                                "WHERE category_i18n.category_id = category.category_id ".
                                "AND active=1 AND language_code = '".mysql_escape_string($default)."' ".
                                "AND category_i18n.category_id = " .$category." ".
                                "LIMIT 1 ".
                        ") as category_i18n_id ".
                        "FROM category ".
                        "WHERE category_id=".$category.
                     ")";

            $c = new Criteria();
            $c->add(self::CATEGORY_I18N_ID, $union, Criteria::CUSTOM);
            $c->setLimit(1);

            self::$categories[$category] = self::doSelectOne($c);

        }

        return self::$categories[$category];

    }

} // CategoryI18nPeer
